/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    //加载菜单
    var selMenu = $.Params.create();
    selMenu.addParams("parentId","0");
    selMenu.ajax(getIP()+"powerMenu/getMenus",function(data){
        if(data.success){
            var html="";
            $.each(data.result,function(i,val){
               html += "<div><input type='checkbox' eid = '"+val.id+"' parentId='0' class='minimal'>"+val.menuName+"";
                var rows = val.menus;
                if(rows.length > 0){
                    $.each(rows,function(j,obj){
                        html+="<p style='margin-left: 20px;'><input type='checkbox' eid = '"+obj.id+"' parentId='"+val.id+"' class='minimal' >"+obj.menuName+"</p>";
                    })
                }
                html+="</div>";
            })
            $("#menu").html(html);
        }
    })


    //添加信息
    $("#eid").val(getUUID());
    $("#parentId").val("0");
    $("#updateTime").val(getNowDateTime());
    $("#updateUserName").val("fred");
    $("#addData").on("click",function(){
        var roleName = $("#roleName").val().trim();
        var len =  $("#menu").find("input:checked").length;
        var ids = "";
        if(roleName ==""){
            alert("请输入角色名称！");
            return false;
        }

        if(len == 0){
            alert("请选择权限！");
            return false;
        }else{
            $("#menu input:checked").each(function(){
                ids+=$(this).attr("eid")+",";
            })
            ids = ids.substring(0,ids.lastIndexOf(","));
        }

      $("#idStr").val(ids);

        $("#addForm").attr("action",getIP()+"powerRole/addPowerRole");
        $("#addForm").submit();
    })


    //取消修改信息
    $("#cancelAdd").on("click",function() {
        history.back(-1);
    })


});